<template>
	<view class="mainpadding beijingse">
		<!-- <view class="notitletext textright" @click="tzfhmx">返还明细</view> -->
		<!-- 筛选弹出层 -->
		<u-popup :show="show" @close="close" mode="bottom" :round="10">
			<view class="mainpadding">
				<view class="titletext textcenter">筛选</view>
				<view class="">
					<view class="margin_top strongtext">类型</view>
					<view class="flexleft flex_wrap">
						<view class="flexcenter sanshi margin_top2" v-for="item in lx" :key="item.id" @click="changelx(item.id)">
							<view :class="item.id==lxcurrent?'haungsebtn':'huisebtn'">
								{{item.name}}
							</view>
						</view>
					</view>
				</view>
				<view class="margin_top strongtext">时间</view>
				<view class="flexleft flex_wrap">
					<view class="flexcenter sanshi margin_top2" v-for="item in timeList" :key="item.id" @click="changesj(item.id)">
						<view :class="item.id==selecttime?'haungsebtn':'huisebtn'">
							{{item.name}}
						</view>
					</view>
				</view>
				<!-- 时间 -->
				<view class="margin_top strongtext">自定义时间</view>
				<view class="flexcenter margin_top2" @click="zdysj">
					<view class="shijianbtn margin_right3" @click="zshijian">{{startime}}</view>
					<view class="xian margin_right3"></view>
					<view class="shijianbtn" @click="yshijian">{{endtime}}</view>
				</view>
				<u-datetime-picker :show="zshow" @confirm="zconfirm" v-model="value1" mode="date"
					@cancel="zshow= false"></u-datetime-picker>
				<u-datetime-picker :show="yshow" @confirm="yconfirm" v-model="value2" mode="date" @cancel="yshow= false"
					:minDate="mindate"></u-datetime-picker>
				<view class="bigbtn margin_top" @click="close(1)">确认</view>
			</view>
		</u-popup>
		<view class="toububjt margin_top">
			<view class="bigbtext textcenter" v-if="valueType==0">{{personInfo.bonus_price}}</view>
			<view class="xbtext margin_top1 textcenter" v-if="valueType==0">奖金</view>
			<view class="bigbtext textcenter" v-if="valueType==1">{{personInfo.integral_price}}</view>
			<view class="xbtext margin_top1 textcenter" v-if="valueType==1">积分</view>
			<view class="bigbtext textcenter" v-if="valueType==2">{{personInfo.token_price}}</view>
			<view class="xbtext margin_top1 textcenter" v-if="valueType==2">通证</view>
			<view class="bigbtext textcenter" v-if="valueType==3">{{personInfo.voucher_price}}</view>
			<view class="xbtext margin_top1 textcenter" v-if="valueType==3">福利券</view>
			<view class="flexcenter  margin_top6">
				<view class="baibtn margin_right2" v-if="valueType==0 && jjzz" @click="tzzz">转赠</view>
				<view class="baibtn margin_right2" v-if="valueType==1 && jfzz" @click="tzzz">转赠</view>
				<view class="baibtn margin_right2" v-if="valueType==0 && jjzh" @click="tzzh">转换</view>
				<view class="baibtn margin_right2" v-if="valueType==1 && jfzh" @click="tzzh">转换</view>
				<view class="baibtn" @click="tztxclick" v-if="valueType!=3 && valueType!=2">提现</view>
				<view class="baibtn" @click="tztxclick" v-if="valueType==2 && tztx">提现</view>
				<view class="baibtn" v-if="valueType==3" @click="tzsplb(2)">去消费</view>
			</view>
		</view>
		<view class="flexbetween margin_top">
			<view class="dingwei">
				<view class="titletext" v-if="valueType==0">余额明细</view>
				<view class="titletext" v-if="valueType==1">积分明细</view>
				<view class="titletext" v-if="valueType==2">通证明细</view>
				<view class="titletext" v-if="valueType==3">福利券</view>
				<view class="zitbjs"></view>
			</view>
			<view class="flexright" @click="show = true">
				<view class="zhtext margin_right1">筛选</view>
				<view class="shaxicon"></view>
			</view>
		</view>
		<!--筛选内容 -->
		<view class="zwtimg flexcenter" v-if="!list.data.length">
			<image src="../../static/image/system/zwt.png" mode=""></image>
		</view>
		<view class="ffffff mainpadding radius mainpadding margin_top" v-if="list.data.length">
			<view class="xiahuax" v-for="item in list.data" :key="item.id">
				<view class="flexbetween">
					<view class="ershib1">{{item.memo}}</view>
					<view class="qianshu" v-if="valueType==0">{{item.bonus_price}}</view>
					<view class="qianshu" v-if="valueType==1">{{item.integral_price}}</view>
					<view class="qianshu" v-if="valueType==2">{{item.token_price}}</view>
					<view class="qianshu" v-if="valueType==3">{{item.voucher_price}}</view>
				</view>
				<view class="margin_top1 qhtext">{{item.createtime_text}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				valueType: 0, //0奖金，1积分，2通证，3福利券
				// 时间
				startime: "开始时间",
				endtime: "结束时间",
				// 数据列表
				show: false,
				mindate: "",
				//开始时间
				zshow: false,
				value1: Number(new Date()),
				//结束
				yshow: false,
				value2: Number(new Date()),
				// 筛选
				timeList: [{
						id: 1,
						name: "今日"
					},
					{
						id: 2,
						name: "昨日"
					},
					{
						id: 3,
						name: "本月"
					},
					{
						id: 4,
						name: "上月"
					}
				],
				// 类型
				lx: [{
						id: 1,
						name: "收入"
					},
					{
						id: 2,
						name: "支出"
					},
					{
						id: 3,
						name: "转增"
					},
					{
						id: 4,
						name: "转换"
					}
				],
				lxcurrent:"",
				selecttime: 0, //筛选时间类型
				personInfo: {
					bonus_price: "",
					integral_price: "",
					token_price: "",
					voucher_price: "",
				},
				page: 1,
				limit: 12,
				list: {
					data: [{
						bonus_price:"",
						integral_price:"",
						token_price: "",
						voucher_price: "",
						memo:"",
						createtime_text:"",
					}]
				},
				type:"",
				jjzz:false,//奖金转增开关
				jjzh:false,//奖金转换开关
				jfzz:false,//积分转增开关
				jfzh:false,//积分转换开关
				tztx:false,//通证提现开关
			}
		},
		// 跳转返还明细
		onNavigationBarButtonTap(e) {
			uni.navigateTo({
				url: '/pages/mypage/fanhuanmx'
			})
		},
		onLoad(options) {
			this.valueType = options.type
			// this.type = options.id
			let text = ""
			if(this.valueType==0){
				text="奖金"
			}else if(this.valueType==1){
				text="积分"
			}else if(this.valueType==2){
				text="通证"
			}else if(this.valueType==3){
				text="福利券"
			}
			uni.setNavigationBarTitle({
			    title: text
			});
		},
		onShow() {
			this.getpz()
			this.init()
		},
		methods: {
			getpz(){
				httpRequest.request('/api/index/getConfigInfo', 'POST', {}, false, false, true).then(res => {
					this.getinfo()
					// 奖金转增
					if(res.data.bonus_zz_status==1){
						this.jjzz = true
					}
					// 奖金转换
					if(res.data.bonus_zh_status==1){
						this.jjzh = true
					}
					// 积分转增开关
					if(res.data.integral_zz_status==1){
						this.jfzz = true
					}
					// 积分转换开关
					if(res.data.integral_zh_status==1){
						this.jfzh = true
					}
					// 通证提现开关
					if(res.data.token_th_status==1){
						this.tztx = true
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			getinfo() {
				httpRequest.request('/api/user/index', 'POST', {}, false, false, true).then(res => {
					this.personInfo = res.data
					// 奖金转增
					if(this.jjzz==false){
						if(res.data.bonus_zz_status==1){
							this.jjzz=true
						}else{
							this.jjzz=false
						}
					}
					// 奖金转换
					if(this.jjzh==false){
						if(res.data.bonus_zh_status==1){
							this.jjzh=true
						}else{
							this.jjzh=false
						}
					}
					// 积分转增
					if(this.jfzz==false){
						if(res.data.integral_zz_status==1){
							this.jfzz=true
						}else{
							this.jfzz=false
						}
					}
					// 积分转换
					if(this.jfzh==false){
						if(res.data.integral_zh_status==1){
							this.jfzh=true
						}else{
							this.jfzh=false
						}
					}
					// 通证提现
					if(this.jfzh==false){
						if(res.data.token_th_status==1){
							this.jfzh=true
						}else{
							this.jfzh=false
						}
					}
					
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			tzsplb(value) {
				let msg = {
					keywords: "",
					category_id: "", //分类id
					type:value//1,普通商品，2福利券商品
				}
				uni.navigateTo({
					url: "/pages/homepage/shangplb?msg=" + encodeURIComponent(JSON.stringify(msg))
				})
			},
			// 热门推荐列表
			init(isPage, page) {
				let _this = this;
				let url = ""
				if (this.valueType == 0) {
					url = "/api/user/userBonuspriceLog"
				} else if (this.valueType == 1) {
					url = "/api/user/userIntegralpriceLog"
				} else if (this.valueType == 2) {
					url = "/api/user/userTokenpriceLog"
				} else if (this.valueType == 3) {
					url = "/api/user/userVoucherpriceLog"
				}
				httpRequest.request(url, 'POST', {
					type_status: this.lxcurrent, //明细类型
					start_time: this.startime=="开始时间"?'':this.startime,
					end_time: this.endtime=="结束时间"?'':this.endtime,
					sx_type: this.selecttime, //筛选类型
					page: page || 1,
					limit: this.limit,
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			// 类型切换
			changelx(id){
				this.lxcurrent = id
			},
			// 时间转换
			changesj(id){
				this.mindate = ""
				this.selecttime = id
				this.startime = "开始时间"
				this.endtime = "结束时间"
			},
			
			// 跳转提现
			tztxclick() {
				uni.navigateTo({
					url: '/pages/mypage/tixian?type='+this.valueType
				})
			},
			// 跳转转换页面
			tzzh() {
				uni.navigateTo({
					url: '/pages/mypage/zhuanhuan?type='+this.valueType
				})
			},
			// 跳转转增页面
			tzzz() {
				uni.navigateTo({
					url: '/pages/mypage/zhuanzeng?type='+this.valueType
				})
			},
			// 选择时间段
			selecTimeBtn(id) {
				this.mindate = ""
				this.selecttime = id
				this.startime = "开始时间"
				this.endtime = "结束时间"
			},
			date(timer) {
				var date = new Date(timer); //当前时间
				var year = date.getFullYear() //返回指定日期的年份
				var month = repair(date.getMonth() + 1); //月
				var day = repair(date.getDate()); //日
				var curTime = year + "-" + month + "-" + day

				function repair(i) {
					if (i >= 0 && i <= 9) {
						return "0" + i;
					} else {
						return i;
					}
				}
				return curTime
			},
			zdysj() {
				this.selecttime = 0
			},
			// 开始时间
			zconfirm(e) {
				console.log(e)
				this.mindate = e.value
				this.startime = this.date(e.value)
				this.zshow = false
			},
			zshijian() {
				this.zshow = true
			},
			//结束时间
			yconfirm(e) {
				console.log(e)
				this.endtime = this.date(e.value)
				this.yshow = false
			},
			yshijian() {
				if (this.mindate == "") {
					httpRequest.toast("请选择开始时间")
					return
				}
				this.yshow = true
			},
			close(value) {
				if(value==1){
					this.init()
				}
				this.show = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.xian {
		width: 22rpx;
		height: 0rpx;
		background-color: #999999;
		border: 1rpx solid #999999;
	}

	.shijianbtn {
		padding: 20rpx 65rpx;
		background: #F7F9FA;
		border-radius: 41rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.huisebtn {
		width: 198rpx;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
		background: #F7F9FA;
		border-radius: 41rpx;
	}

	.haungsebtn {
		width: 198rpx;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FAB536;
		background: rgba(250, 181, 54, .1);
		border-radius: 41rpx;
	}

	.sanshi {
		width: 33.33%;
	}

	.xiahuax {
		margin-top: 30rpx;
		padding-bottom: 30rpx;
		border-bottom: 2rpx solid rgba(0, 0, 0, 0.03);
	}

	.xiahuax:first-child {
		margin-top: 0rpx;
	}

	.xiahuax:last-child {
		padding-bottom: 0rpx;
		border-bottom: none;
	}

	.qhtext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.qianshu {
		font-size: 32rpx;
		font-family: DIN Next LT Pro-Bold, DIN Next LT Pro;
		font-weight: bold;
		color: #FAB536;
	}

	.ershib1 {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #333333;
	}

	.shaxicon {
		width: 12rpx;
		height: 10rpx;
		background-size: 100% 100%;
		background-image: url('../../static/image/system/shaixuan.png');
	}

	.zhtext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.banju {
		padding: 30rpx 30rpx 20rpx;
	}

	.line {
		width: 100%;
		border: 1rpx solid rgba(255, 255, 255, .1);
	}

	.baibtn {
		width: 194rpx;
		height: 65rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 10rpx;
		border: 2rpx solid #FFFFFF;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}

	.xbtext {
		font-size: 36rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}

	.bigbtext {
		font-size: 80rpx;
		font-family: DIN Next LT Pro-Bold, DIN Next LT Pro;
		font-weight: bold;
		color: #FFFFFF;
	}

	.toububjt {
		background-size: 100% 100%;
		width: 100%;
		box-sizing: border-box;
		padding: 76rpx 0 20rpx;
		background-image: url('../../static/image/system/jjtb.png');
	}
</style>
